from sqlalchemy import Column, String, DateTime, Integer, Text, ForeignKey
from sqlalchemy.types import CHAR
from database import Base
import uuid
from datetime import datetime
from pydantic import BaseModel
from typing import Optional


class Video(Base):
    __tablename__ = "videos"

    # For SQLite compatibility, use CHAR(32) to store UUID as string
    id = Column(CHAR(32), primary_key=True, default=lambda: str(uuid.uuid4()).replace('-', ''))
    filename = Column(String, nullable=False)
    file_path = Column(String, nullable=False)
    project_id = Column(CHAR(32), ForeignKey("projects.id"), nullable=True)
    size = Column(Integer)  # File size in bytes
    duration = Column(Integer, nullable=True)  # Duration in seconds
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)


class VideoCreate(BaseModel):
    filename: str
    file_path: str
    project_id: Optional[str] = None
    size: Optional[int] = None
    duration: Optional[int] = None


class VideoUpdate(BaseModel):
    filename: Optional[str] = None
    file_path: Optional[str] = None
    project_id: Optional[str] = None
    size: Optional[int] = None
    duration: Optional[int] = None
